import 'package:flutter/material.dart';

import '../../repository/api.dart';
import '../../repository/dto/Knowledge_detail_dto.dart';
import '../../repository/dto/Knowledge_tree_dto.dart';

class KnowledgeViewModel with ChangeNotifier {
  List<KnowledgeTreeItem?>? knowledgeTree;
  List<KnowledgeDetailItem?>? knowledgeDetail = [];
  int curPage = 0;

  Future<void> getKnowledgeTree() async {
    knowledgeTree = await Api.instance.getKnowledgeTree();    
    notifyListeners();
  }

  Future<void> getKnowledgeDetail({required int id, bool isMore = false}) async {
    if(isMore == true) {
      curPage++;
    } else {
      curPage = 0;
      knowledgeDetail?.clear();
    }
    List<KnowledgeDetailItem?> data = await Api.instance.getKnowledgeDetail(id, curPage);
    knowledgeDetail?.addAll(data);
    notifyListeners();  
  }
}